function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function t(e, t, n) {
    return t in e ? Object.defineProperty(e, t, {
        value: n,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = n, e;
}

function n(e) {
    var t = {};
    return Object.keys(e).forEach(function(n) {
        var r = e[n].val;
        t[n] = r;
    }), t;
}

function r(e) {
    return e.items.every(function(e) {
        return e.status;
    });
}

function o(e) {
    return u.default.site.site.view({
        data: {
            sid: e
        }
    }).catch(function(e) {
        if (-100005 === e.code) throw new Error("该官网已被删除，无法进行支付");
        return Promise.reject(e);
    });
}

function c(e, t, n) {
    var r = getApp().globalData, o = r.app, c = r.appid, a = {
        openid: r.tokens.openid,
        appid: c,
        app: "site" === o ? "site" : +n,
        from: "site_product",
        fee: e,
        orderid: "" + t
    };
    return u.default.v4.wechatpay.prepay({
        data: a,
        query: {
            app: a.app
        },
        desc: "预支付创建"
    });
}

function a(e) {
    return new Promise(function(t, n) {
        wx.requestPayment(Object.assign({}, e, {
            success: function(e) {
                wx.showToast({
                    title: "支付成功",
                    icon: "success"
                }), t(e);
            },
            fail: function(e) {
                var t = e.errMsg;
                if (!/cancel/.test(t)) throw new Error(t);
            }
        }));
    });
}

function i(e) {
    var t = e.id, n = e.sid, r = e.formid, o = e.refundCb, c = function(e) {
        return l.default.qAlert(e, "退款提示", "我知道了");
    };
    l.default.collectFormid(r), u.default.site.productorder.refundv2({
        data: {
            id: t,
            sid: n,
            formid: r
        }
    }).then(function() {
        wx.showToast({
            title: "已同意退款"
        }), o && o();
    }).catch(function(e) {
        console.log(e), c(e.message);
    });
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var d, u = e(require("./api2")), l = e(require("./util")), s = e(require("../public/components/modalview/modalview")), f = e(require("/../public/components/dialog/dialog")), p = 1209600, m = {
    unpaid: {
        val: 0,
        desc: "待支付"
    },
    paid: {
        val: 1,
        desc: "待发货"
    },
    deliver: {
        val: 10,
        desc: "已发货"
    },
    done: {
        val: 2,
        desc: "已完成"
    },
    cancel: {
        val: 3,
        desc: "已取消"
    },
    refund: {
        val: 11,
        desc: "退款"
    },
    confirm: {
        val: 12,
        desc: "已收货"
    }
}, h = {
    none: {
        val: 0,
        desc: ""
    },
    apply: {
        val: 5,
        desc: "申请退款中"
    },
    applyAfterSale: {
        val: 11,
        desc: "申请售后中"
    },
    refunded: {
        val: 6,
        desc: "已同意退款"
    },
    rejected: {
        val: 7,
        desc: "已拒绝退款"
    },
    refunding: {
        val: 13,
        desc: "退款中"
    },
    refundSuccess: {
        val: 14,
        desc: "退款成功"
    },
    refundFail: {
        val: 8,
        desc: "退款失败"
    }
}, v = function(e) {
    var t = [];
    return Object.keys(e).forEach(function(n) {
        var r = e[n], o = r.val, c = r.desc;
        t[o] = c;
    }), t;
}(m), w = n(m), E = n(h), x = {
    COMPLETE: "complete",
    PAY: "pay",
    CANCEL: "cancel",
    DEL: "del",
    DELIVER: "deliver",
    CONFIRM: "confirm",
    REFUND_APPLY: "refund_apply",
    REFUND_APPLY_AFTERSALE: "refund_apply_aftersale",
    REFUND_REJECT: "refund_reject",
    REFUND_DONE: "refund_done"
}, y = (d = {}, t(d, x.COMPLETE, "done"), t(d, x.PAY, "paid"), t(d, x.CANCEL, "cancel"), 
t(d, x.DELIVER, "deliver"), t(d, x.CONFIRM, "confirm"), t(d, x.REFUND_APPLY, "apply"), 
t(d, x.REFUND_APPLY_AFTERSALE, "applyAfterSale"), t(d, x.REFUND_REJECT, "rejected"), 
t(d, x.REFUND_DONE, "refunded"), d), _ = [ {
    name: "全部",
    status: "all"
} ].concat(Object.keys(m).filter(function(e) {
    return "cancel" !== e && "confirm" !== e;
}).map(function(e) {
    return {
        name: m[e].desc,
        status: e
    };
})), F = {
    contents: [ {
        type: "text",
        text: "退款确认",
        style: "font-size: 18px; color: #000; line-height: 2;"
    }, {
        type: "text",
        text: "确定后，请登陆微信支付商户平台，交易中心-交易订单，处理退款。"
    }, {
        type: "text",
        text: "(https://pay.weixin.qq.com)",
        style: "color: #09bb07",
        selectable: !0
    } ],
    buttons: [ {
        text: "取消",
        type: "default"
    }, {
        text: "确定"
    } ]
};

exports.default = {
    orderNavTags: _,
    orderStatusMap: w,
    refundStatusMap: E,
    orderDescList: v,
    orderAction: x,
    actionResultStatusMap: y,
    REFUND_REASON_PATH: "https://oss.ibos.cn/common/json/site/refund_reason.json",
    delOrder: function(e, t, n, r) {
        l.default.collectFormid(t);
        var o = "profile" === r ? "my" : "manage";
        wx.showModal({
            title: "操作提醒",
            content: "确定删除该笔订单？",
            success: function(t) {
                t.confirm && u.default.site.productorder.del({
                    data: {
                        orderid: e,
                        op: o
                    },
                    desc: "删除订单"
                }).then(function() {
                    wx.showToast({
                        title: "订单删除成功"
                    }), n && n();
                });
            }
        });
    },
    deliverOrder: function(e, t, n) {
        l.default.collectFormid(t), u.default.site.productorder.deliver({
            data: e,
            desc: "订单状态更新"
        }).then(function() {
            wx.showToast({
                title: "订单已发货"
            }), n && n();
        });
    },
    confirmOrder: function(e, t, n) {
        l.default.collectFormid(t), wx.showModal({
            title: "操作提醒",
            content: "请确认您已收到货物？",
            success: function(t) {
                t.confirm && u.default.site.productorder.confirmreceipt({
                    data: {
                        orderid: e
                    },
                    desc: "订单状态更新"
                }).then(function() {
                    wx.showToast({
                        title: "已收货"
                    }), n && n();
                });
            }
        });
    },
    completeOrder: function(e, t) {
        wx.showModal({
            title: "操作提醒",
            content: "确定已完成这笔订单？",
            success: function(n) {
                n.confirm && u.default.site.productorder.completev2({
                    data: {
                        orderid: e
                    },
                    desc: "订单状态更新"
                }).then(function() {
                    wx.showToast({
                        title: "已完成这笔订单"
                    }), t && t();
                });
            }
        });
    },
    cancelOrder: function(e, t, n) {
        l.default.collectFormid(t), wx.showModal({
            title: "操作提醒",
            content: "确定取消该笔订单？",
            success: function(t) {
                t.confirm && u.default.site.productorder.cancel({
                    data: {
                        orderid: e
                    },
                    desc: "取消订单"
                }).then(function() {
                    wx.showToast({
                        title: "订单已取消"
                    }), n && n();
                });
            }
        });
    },
    cancelOrderByMerchant: function(e, t, n, r) {
        l.default.collectFormid(n), wx.showModal({
            title: "操作提醒",
            content: "确定取消该笔订单？",
            success: function(n) {
                n.confirm && u.default.site.productorder.merchantcancel({
                    data: {
                        id: e,
                        sid: t
                    },
                    desc: "取消订单"
                }).then(function() {
                    wx.showToast({
                        title: "订单已取消"
                    }), r && r();
                });
            }
        });
    },
    payOrder: function(e) {
        var t = e.sid, n = e.id, i = e.order, d = e.formid, u = e.payCb, s = getApp().globalData.app, f = function(e) {
            return l.default.qAlert(e, "支付提示", "我知道了");
        };
        if (!r(i)) return f("订单关联产品已被删除");
        l.default.collectFormid(d);
        var p = i.app, m = i.appname;
        return 0 == +p && "thirdparty" === s ? f("该订单是在“小官网”小程序创建的，请前往“小官网”--“我的订单”支付") : 1 == +p && "site" === s ? f("该订单是在“" + (m || "独立") + "小程序”创建的，请前往“" + (m || "独立") + "小程序”--“我的订单”支付") : void o(t).then(function(e) {
            var t = e.mchid;
            if ("thirdparty" === s && 0 === t) throw new Error("商家未配置微信支付，无法完成在线支付");
            return c(i.total_fee, n, t);
        }).then(function(e) {
            return a(e.jsparams);
        }).then(function() {
            u && u();
        }).catch(function(e) {
            console.log(e), f(e.message);
        });
    },
    rejectRefund: function(e, t, n, r, o) {
        f.default.prompt({
            scope: t,
            title: "拒绝退款理由",
            type: "textarea",
            placeholder: "请输入拒绝理由",
            placeholderStyle: "font-size: 15px;",
            maxlength: -1,
            onConfirm: function(c) {
                var a = e.data["" + t].content;
                if (!a) return !1;
                u.default.site.productorder.rejectrefund({
                    data: {
                        id: n,
                        formid: r,
                        rejectreason: a
                    }
                }).then(function() {
                    wx.showToast({
                        title: "已拒绝退款"
                    }), o && o(a);
                });
            }
        }), l.default.collectFormid(r);
    },
    refund: function(e, t) {
        if ("site" === getApp().globalData.app) {
            var n = t.refund;
            wx.showModal({
                title: "操作提示",
                content: "退款金额：" + n / 100 + "元，同意退款后，系统会自动将退款金额返还至买家的微信钱包，请确认退款金额无误后再进行操作。是否同意退款？",
                confirmText: "同意",
                success: function(e) {
                    e.confirm && i(t);
                }
            });
        } else e.$$refundGuideModal ? e.$$refundGuideModal.show() : (F.buttons[1].tap = function() {
            return i(t);
        }, e.$$refundGuideModal = (0, s.default)(e, F));
    },
    isWithinFortnight: function(e) {
        var t = new Date(e.replace(/-/g, "/"));
        return Math.round((Date.now() - t) / 1e3) <= p;
    }
};